package com.itheima01;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class UDPServies {
    public static void main(String[] args) throws Exception {
//        DatagramSocket socket=new DatagramSocket(8888);
//
//        byte[] bytes = new byte[1024];
//
//        DatagramPacket packet=new DatagramPacket(bytes,bytes.length);
//
//        socket.receive(packet);
//
//        int length = packet.getLength();
//
//        String s = new String(bytes, 0, length);
//
//        System.out.println(s);
//
//        socket.close();
        DatagramSocket socket=new DatagramSocket(8888);
        while (true) {
            byte[] bytes = new byte[1024];
            DatagramPacket packet=new DatagramPacket(bytes,bytes.length);
            socket.receive(packet);
            int length = packet.getLength();
            String s = new String(bytes, 0, length);
            System.out.println(s);
        }

//        socket.close();
    }
}
